package ilearn.job.disserver.acconut;

import ilearn.job.disserver.acconut.entity.Account;
import ilearn.job.disserver.acconut.repository.AccountRepository;
import ilearn.job.disserver.sdk.account.AccountCache;
import ilearn.job.disserver.sdk.account.dto.AccountDTO;
import lombok.extern.log4j.Log4j2;
import org.springframework.boot.CommandLineRunner;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.math.BigDecimal;

@Component
@Log4j2
public class AccountDataInit implements CommandLineRunner {

    @Resource
    private AccountCache accountCache;
    @Resource
    private AccountRepository accountRepository;
    @Override
    public void run(String... args) throws Exception {
        log.info("数据初始化开始");
        Account account = Account.builder().id(1L).name("枭首").age(29).bal(new BigDecimal("112.3")).build();
        accountRepository.save(account);
        account = Account.builder().id(2L).name("未成年").age(17).bal(new BigDecimal("12.3")).build();
        accountRepository.save(account);
        account = Account.builder().id(3L).name("退休").age(60).bal(new BigDecimal("212.3")).build();
        accountRepository.save(account);
        AccountDTO accountDTO = AccountDTO.builder().build();
        account.fillAccountDTO(accountDTO);
        accountCache.updateAccount(accountDTO);

    }
}
